package com.ihr360.payroll.model.dto.salary.report;

import com.ihr360.hibernate.type.encrypt.JsonEncryptType;
import com.ihr360.payroll.model.dto.salary.task.period.embeddable.StaffSalarySnapshot;
import com.ihr360.payroll.model.dto.salary.task.period.embeddable.StaffSalarySnapshotListWrapper;
import com.ihr360.payroll.model.dto.salary.task.period.embeddable.StaffSalaryTermId;
import com.ihr360.shared.entitywithlistener.TimeEntity;
import com.vladmihalcea.hibernate.type.json.JsonStringType;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;

import javax.persistence.Column;
import javax.persistence.EmbeddedId;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

/**
 * Created by Eric on 2018/5/14/014.
 * 合并报表计算结果保存
 */
@Entity
@TypeDefs({
        @TypeDef(name = "json", typeClass = JsonStringType.class),
        @TypeDef(name = "json-encrypt", typeClass = JsonEncryptType.class)
})
@Getter
@Setter
@DynamicUpdate
@Table(
        indexes = {@Index(name = "company_staff_index", columnList = "companyId,staffId,term_id", unique = true)})
public class MergeReportStaffSalary extends TimeEntity {
    @EmbeddedId
    StaffSalaryTermId id;

    @Column(length = 40, nullable = false)
    private String companyId;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(nullable = false)
    private MergeSalaryReportTermSalary termSalary;


    @Column(columnDefinition = "text")
    @Type(type = "json-encrypt")
    private StaffSalarySnapshot summarizedData;

    @Column(columnDefinition = "text")
    @Type(type = "json-encrypt")
    private StaffSalarySnapshotListWrapper phasedData;
}
